import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;

/**
 * I represent a button
 * @author Hugo Armando Rodríguez Flores
 * @version May 15th 2013
 */
public class Boton extends Actor
{
    private ArrayList<GreenfootImage> buttons;  //ArrayList that holds the images for the buttons
    private int button; //Number of the current button
    private MouseInfo mouse;    //MouseInfo object used to retrive information from the mouse

    /**
     * Sets all the corresponding properties for this button.
     */
    public Boton(int aButton)
    {
        buttons=new ArrayList<GreenfootImage>();
        String tempString=new String();
        for (int i=0; i<10; i++)
        {
            tempString="bot"+(i+1)+".png";
            buttons.add(new GreenfootImage(tempString));
        }
        this.setImage(buttons.get(aButton));
        button=aButton;
    }

    /**
     * Makes the button act in the world.
     */
    public void act()
    {
        mouse=Greenfoot.getMouseInfo();
        this.option();
        if (mouse!=null)
            this.animation();
    }

    /**
     * When the mouse is over a button, this method will set a new image for itself.
     */
    public void animation()
    {
        int imageInCellsX=buttons.get(button).getWidth(), imageInCellsY=buttons.get(button).getHeight();
        if(this.getWorld()!=null)
        {
            int imageX=this.getX()-(imageInCellsX/2), imageY=this.getY()-(imageInCellsY/2);
            if (mouse.getX()>imageX && mouse.getY()>imageY && mouse.getX()<imageX+imageInCellsX && mouse.getY()<imageY+imageInCellsY)
                this.setImage(buttons.get(button+5));
            else
                this.setImage(buttons.get(button));
        }
    }

    /**
     * When the mouse is clicked, this method will transfer the corresponding option to a method in the world.
     */
    public void option()
    {
        World world=getWorld();

        if(Greenfoot.mouseClicked(this))
        {
            switch(button)
            {
                case 0:
                Greenfoot.setWorld(new Nivel1());
                break;
                case 1:
                Greenfoot.setWorld(new Help());
                break;
                case 2:
                Greenfoot.setWorld(new AcercaDe());
                break;
                case 3:
                if(UserInfo.isStorageAvailable())
                    Greenfoot.setWorld(new Records());
                else
                    Greenfoot.setWorld(new Server());
                break;
                case 4:
                Greenfoot.setWorld(new Menu());
                break;

            }
        }
    }
}